package com.itheima.rabbitmq.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author : [chenxys]
 * @version : [v1.0]
 * @Description :
 * @createTime : [2022/6/22 20:13]
 */
public class ConnectionUtil {
    public static Connection getConnection() throws Exception {
     // 1、创建连接工厂
     ConnectionFactory factory = new ConnectionFactory();

     // 2、设置参数
     // 2.1、设置IP，默认为127.0.0.1
     factory.setHost("127.0.0.1");
     // 2.2、设置端口，默认为5672
     factory.setPort(5672);
     // 2.3、设置虚拟机,默认为/
     factory.setVirtualHost("/itcast");
     // 2.4、设置用户名,默认为guest
     factory.setUsername("heima");
     // 2.5、设置密码,默认为guest
     factory.setPassword("heima");

     // 3、创建连接 Connection
     return factory.newConnection();
    }
}
